package mf.com.controller.product;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import mf.com.Service.Product.BrandService;
import mf.com.entity.product.Brand;
import mf.com.log.annotation.Log;
import mf.com.vo.common.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: lmf
 * @Create: 2024/3/31 21:57
 * Description:  品牌控制层
 */
@RestController
@RequestMapping("/admin/product/brand")
@Tag(name = "品牌管理")
public class BrandController {
    @Resource
    private BrandService brandService;

    @GetMapping("/{pageNum}/{pageSize}")
    @Operation(summary = "查询所有品牌分页")
    public Result<PageInfo<Brand>> selectAll(@PathVariable("pageNum") Integer pageNum,
                                             @PathVariable("pageSize") Integer pageSize)
                                         {
        return  Result.success(brandService.selectAll(pageNum,pageSize));
    }

    @GetMapping("/findAll")
    @Log(title = "我是名称",businessType = 0)
    @Operation(summary = "查询所有品牌")
    public Result<List<Brand>> findAll(){
        return  Result.success(brandService.findAll());
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary = "根据ID删除品牌")
    public Result<Integer> delete(@PathVariable Long id) {
        return Result.success(brandService.deleteById(id));
    }

    @PutMapping("update")
    @Operation(summary = "修改品牌")
    public Result<Integer> update(@RequestBody Brand brand) {
        return Result.success(brandService.update(brand));
    }

    @PostMapping("save")
    @Operation(summary = "新增品牌")
    public Result<Integer> save(@RequestBody Brand brand) {
        return Result.success(brandService.save(brand));
    }
}
